<template>
  <!-- 底部部分 => list有数据的时候，才展示  list.length > 0 -->
  <footer v-show="list.length>0" class="footer">
    <span class="todo-count"><strong>{{num}}</strong>剩余</span>
    <ul class="filters">
      <li>
        <a :class="{selected:state==='all'}" @click="$emit('show-list','all')" href="#/">全部</a>
      </li>
      <li>
        <a :class="{selected:state==='doing'}" @click="$emit('show-list','doing')" href="#/active">进行中</a>
      </li>
      <li>
        <a :class="{selected:state==='do'}" @click="$emit('show-list','do')" href="#/completed">已完成</a>
      </li>
    </ul>
    <!-- 有已完成的任务，才需要显示这个按钮 -->
    <button v-if="flag" @click="$emit('del-all')" class="clear-completed">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props: {
    list: {
      type:Array,
      required:true,
      default: () => []
    },
    state:String
  },
  computed: {
    num() {
      return this.list.filter(item => item.done === false).length
    },
    flag() {
      return this.list.some(item => item.done === true)
    }
  }
}
</script>

<style></style>
